<?php
/* --------------------------------------------------------------
   $Id: new_category.php,v 1.1 2010/09/08 10:50:55 akausch Exp $

   XT-Commerce - community made shopping
   http://www.xt-commerce.com

   Copyright (c) 2003 XT-Commerce
   --------------------------------------------------------------
   based on:
   (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
   (c) 2002-2003 osCommerce(categories.php,v 1.140 2003/03/24); www.oscommerce.com
   (c) 2003  nextcommerce (categories.php,v 1.37 2003/08/18); www.nextcommerce.org

   Released under the GNU General Public License
   --------------------------------------------------------------
   Third Party contribution:
   Enable_Disable_Categories 1.3               Autor: Mikel Williams | mikel@ladykatcostumes.com
   New Attribute Manager v4b                   Autor: Mike G | mp3man@internetwork.net | http://downloads.ephing.com
   Category Descriptions (Version: 1.5 MS2)    Original Author:   Brian Lowe <blowe@wpcusrgrp.org> | Editor: Lord Illicious <shaolin-venoms@illicious.net>
   Customers Status v3.x  (c) 2002-2003 Copyright Elari elari@free.fr | www.unlockgsm.com/dload-osc/ | CVS : http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/elari/?sortby=date#dirlist

   Released under the GNU General Public License
   --------------------------------------------------------------*/
if ( ($_GET['cID']) && (!$_POST) ) {
	$category_query = xtc_db_query("select * from " .
	                    TABLE_CATEGORIES . " c, " .
	                    TABLE_CATEGORIES_DESCRIPTION . " cd
	                    where c.categories_id = cd.categories_id
	                    and c.categories_id = '" . $_GET['cID'] . "'");

	$category = xtc_db_fetch_array($category_query);
	$cInfo = new objectInfo($category);
	
} elseif ($_POST) {
	$cInfo = new objectInfo($_POST);
	$categories_name = $_POST['categories_name'];
	$categories_url_alias = $_POST['categories_url_alias'];
	$categories_heading_title = $_POST['categories_heading_title'];
	$categories_description = $_POST['categories_description'];
	$categories_description_footer = $_POST['categories_description_footer'];
	$categories_pic_alt = $_POST['categories_pic_alt'];
	$categories_meta_title = $_POST['categories_meta_title'];
	$categories_meta_description = $_POST['categories_meta_description'];
	$categories_meta_keywords = $_POST['categories_meta_keywords'];
	
} else {
	$cInfo = new objectInfo(array());
}

$languages = xtc_get_languages();

$text_new_or_edit = ($_GET['action']=='new_category_ACD') ? TEXT_INFO_HEADING_NEW_CATEGORY : TEXT_INFO_HEADING_EDIT_CATEGORY;
?>
<tr>
	<td colspan="2">
		<script type="text/javascript" src="includes/javascript/tabs/jquery.history_remote.pack.js"></script>
		<script type="text/javascript" src="includes/javascript/ui/jquery.core.min.js"></script>
		<script type="text/javascript" src="includes/javascript/ui/jquery.widget.min.js"></script>
		<script type="text/javascript" src="includes/javascript/ui/jquery.tabs.min.js"></script>
		<link rel="stylesheet" href="includes/javascript/ui/css/cseo/jquery-ui-1.8.1.custom.css" type="text/css" media="print, projection, screen">
		<link rel="stylesheet" href="includes/javascript/tabs/jquery.tabs.css" type="text/css" media="print, projection, screen">
		<!--[if lte IE 7]>
		<link rel="stylesheet" href="includes/javascript/tabs/jquery.tabs-ie.css" type="text/css" media="projection, screen">
		<![endif]-->
		<script type="text/javascript">
		<!--
			jQuery(function() {
				jQuery('#tabs').tabs({ fx: { opacity: 'toggle' } });
			});
		//-->
		</script>
		<?php
			$form_action = ($_GET['cID']) ? 'update_category' : 'insert_category';
			echo xtc_draw_form('new_category', FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $_GET['cID'] . '&action='.$form_action, 'post', 'enctype="multipart/form-data"'); 
		?>
		<table class="table_pageHeading" border="0" width="100%" cellspacing="0" cellpadding="0">
			<tr>
				<td class="pageHeading">
					<?php echo sprintf($text_new_or_edit, xtc_output_generated_category_path($current_category_id)); ?>
				</td>
			</tr>
		</table>
	</td>
</tr>
<tr>
	<td colspan="2" align="right">
		<input type="submit" class="button" name="update_category" value="<?php echo BUTTON_SAVE; ?>" style="cursor:pointer" onClick="return confirm('<?php echo SAVE_ENTRY; ?>')">&nbsp;&nbsp;
		<?php echo'<a class="button" onclick="javascript:this.blur()" href="'. xtc_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $_GET['cID']) . '">' . BUTTON_CANCEL . '</a>'; ?>
	</td>
</tr>
<tr>
	<td>
		<h3>Grundeinstellungen</h3>
			<table width="100%" border="0">
				<tr>
					<?php
					$files=array();
					if ($dir= opendir(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/module/categorie_listing/')){
						while (($file = readdir($dir)) !==false) {
							if(is_file( DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/module/categorie_listing/'.$file) and ($file !="index.html")){
								$files[] = array('id' => $file, 'text' => $file);
							}
						}
						closedir($dir);
					}
					$default_array = array();
					if ($content['content_file']=='') {
						$default_array[] = array('id' => 'default','text' => TEXT_SELECT);
						$default_value = $cInfo->categories_template;
						$files = array_merge($default_array,$files);
					} else {
						$default_array[] = array('id' => 'default','text' => TEXT_NO_FILE);
						$default_value = $cInfo->categories_template;
						$files = array_merge($default_array,$files);
					} ?>
					<td class="main"><?php echo TEXT_CHOOSE_INFO_TEMPLATE_CATEGORIE ?></td>
					<td class="main"><?php echo xtc_draw_pull_down_menu('categories_template',$files,$default_value) ?></td>
				</tr>
				<tr>
					<td class="main"><?php echo TEXT_EDIT_STATUS; ?>:</td>
					<td class="main"><?php echo xtc_draw_selection_field('status', 'checkbox', '1',$cInfo->categories_status==1 ? true : false); ?></td>
				</tr>
				<tr>
					<?php
					$order_array = '';
					$order_array = array(array('id' => 'p.products_price','text'=>TXT_PRICES),
  										array('id' => 'pd.products_name','text'=>TXT_NAME),
  										array('id' => 'p.products_ordered','text'=>TXT_ORDERED),
  										array('id' => 'p.products_sort','text'=>TXT_SORT),
										array('id' => 'p.products_date_added','text'=>TXT_AGE),
  										array('id' => 'p.products_weight','text'=>TXT_WEIGHT),
  										array('id' => 'p.products_quantity','text'=>TXT_QTY));
					$default_value = 'pd.products_name';
					?>
					<td class="main"><?php echo TEXT_EDIT_PRODUCT_SORT_ORDER; ?>:</td>
					<td class="main"><?php echo xtc_draw_pull_down_menu('products_sorting',$order_array,$cInfo->products_sorting); ?></td>
				</tr>
				<tr>
					<?php
					$order_array = '';
					$order_array = array(array('id' => 'ASC','text'=>'ASC (aufsteigend)'), array('id' => 'DESC','text'=>'DESC (absteigend)'));
					?>	
					<td class="main"><?php echo TEXT_EDIT_PRODUCT_SORT_ORDER; ?>:</td>
					<td class="main"><?php echo xtc_draw_pull_down_menu('products_sorting2',$order_array,$cInfo->products_sorting2); ?></td>
				</tr>
				<tr>
					<td class="main"><?php echo TEXT_EDIT_SORT_ORDER; ?></td>
					<td class="main"><?php echo xtc_draw_input_field('sort_order', $cInfo->sort_order, 'size="2"'); ?></td>
				</tr>
				<tr>
					<td class="main" valign="top">
						<table width="100%">
							<tr>
								<td align="left" valign="top">
									<?php echo TEXT_TEMPLATE_COLUMN; ?>
								</td>
								<td align="right">
									<?php echo xtc_image('images/template_cat.gif', 'Kategorie Seite' , 'align="right"'); ?></td>
								</td>
							</tr>
						</table>
					</td>
			        <td class="main">
						<?php 
							if(isset($_GET['cID'])) {
								echo xtc_draw_selection_field('categories_col_top', 'checkbox', '1', $cInfo->categories_col_top==1 ? true : false).TEXT_TEMPLATE_COLUMN_TOP.'<br />';
								echo xtc_draw_selection_field('categories_col_left', 'checkbox', '1', $cInfo->categories_col_left==1 ? true : false).TEXT_TEMPLATE_COLUMN_LEFT.'<br />'; 
								echo xtc_draw_selection_field('categories_col_right', 'checkbox', '1', $cInfo->categories_col_right==1 ? true : false).TEXT_TEMPLATE_COLUMN_RIGHT.'<br />';
								echo xtc_draw_selection_field('categories_col_bottom', 'checkbox', '1', $cInfo->categories_col_bottom==1 ? true : false).TEXT_TEMPLATE_COLUMN_BUTTON.'<br />';
							} else {
								echo xtc_draw_selection_field('categories_col_top', 'checkbox', '1', true).TEXT_TEMPLATE_COLUMN_TOP.'<br />';
								echo xtc_draw_selection_field('categories_col_left', 'checkbox', '1', true).TEXT_TEMPLATE_COLUMN_LEFT.'<br />'; 
								echo xtc_draw_selection_field('categories_col_right', 'checkbox', '1', true).TEXT_TEMPLATE_COLUMN_RIGHT.'<br />';
								echo xtc_draw_selection_field('categories_col_bottom', 'checkbox', '1', true).TEXT_TEMPLATE_COLUMN_BUTTON.'<br />';
							}	
						?>
									
				<?php
					if(GROUP_CHECK == 'true') {
						$customers_statuses_array = xtc_get_customers_statuses();
						$customers_statuses_array = array_merge(array(array('id'=>'all','text'=>TXT_ALL)),$customers_statuses_array);
						?>
						<tr>
							<td style="border-top: 1px solid;  border-color: #ff0000;" valign="top" class="main" ><?php echo ENTRY_CUSTOMERS_STATUS; ?></td>
							<td style="border: 1px solid; border-color: #ff0000;"  bgcolor="#FFCC33" class="main">
								<?php
								for($i=0;$n=sizeof($customers_statuses_array),$i<$n;$i++) {
									if($category['group_permission_'.$customers_statuses_array[$i]['id']] == 1) {
										$checked='checked ';
									} else {
										$checked='';
									}
									echo '<input type="checkbox" name="groups[]" value="'.$customers_statuses_array[$i]['id'].'"'.$checked.'> '.$customers_statuses_array[$i]['text'].'<br />';
								}
								?>
							</td>
						</tr>
				<?php } ?>
			</table><br />
			<div id="tabs">
				<ul>
					<?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
						<li>
							<a href="#language_<?php echo $i; ?>" onclick="javascript:return false;">
								<span> <?php echo xtc_image('../lang/'.$languages[$i]['directory'].'/'.$languages[$i]['image'], $languages[$i]['name']).' '.$languages[$i]['name']; ?></span>
							</a>
						</li>
					<?php } ?>
				</ul>
				<?php for ($i=0; $i<sizeof($languages); $i++) { ?>
					<div id="language_<?php echo $i; ?>">
						<table width="100%" border="0">
							<tr>
								<td class="main"><?php echo TEXT_EDIT_CATEGORIES_NAME; ?></td>
								<td class="main">
									<?php echo xtc_image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']) . '&nbsp;' . xtc_draw_input_field('categories_name[' . $languages[$i]['id'] . ']', (($categories_name[$languages[$i]['id']]) ? stripslashes($categories_name[$languages[$i]['id']]) : xtc_get_categories_name($cInfo->categories_id, $languages[$i]['id'])),'size=60'); ?>
								</td>
							</tr>
							<tr>
					            <td class="main">URL Alias:</td>
					            <td class="main"><?php echo xtc_image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']) . '&nbsp;' . xtc_draw_input_field('categories_url_alias[' . $languages[$i]['id'] . ']', (($categories_url_alias[$languages[$i]['id']]) ? stripslashes($categories_url_alias[$languages[$i]['id']]) : xtc_get_categories_url_alias($cInfo->categories_id, $languages[$i]['id'])),'size=60').' <a href="#" onclick="javascript:return false;"'.mouseOverJS(HEAD_URL_ALIAS,BODY_URL_ALIAS).'>'.xtc_image(DIR_WS_ICONS.'icon_help.gif').'</a>'; ?></td>
					          </tr>
							<tr>
								<td class="main"><?php echo TEXT_EDIT_CATEGORIES_HEADING_TITLE; ?></td>
								<td class="main">
									<?php echo xtc_image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']) . '&nbsp;' . xtc_draw_input_field('categories_heading_title[' . $languages[$i]['id'] . ']', (($categories_name[$languages[$i]['id']]) ? stripslashes($categories_name[$languages[$i]['id']]) : xtc_get_categories_heading_title($cInfo->categories_id, $languages[$i]['id'])),'size=60'); ?>
								</td>
							</tr>
							<tr>
								<td class="main" valign="top"><?php  echo TEXT_EDIT_CATEGORIES_DESCRIPTION; ?></td>
								<td class="main" valign="top">
									<?php 
									echo xtc_draw_textarea_field('categories_description[' . $languages[$i]['id'] . ']', 'soft', '70', '25', (($categories_description[$languages[$i]['id']]) ? stripslashes($categories_description[$languages[$i]['id']]) : xtc_get_categories_description($cInfo->categories_id, $languages[$i]['id'])));
									echo xtc_wysiwyg('categories_description[' . $languages[$i]['id'] . ']');
									?>
								</td>
							</tr>
							<tr>
								<td class="main" valign="top"><?php  echo TEXT_EDIT_CATEGORIES_DESCRIPTION_FOOTER; ?></td>
								<td class="main" valign="top">
									<?php 
									echo xtc_draw_textarea_field('categories_description_footer[' . $languages[$i]['id'] . ']', 'soft', '70', '25', (($categories_description_footer[$languages[$i]['id']]) ? stripslashes($categories_description_footer[$languages[$i]['id']]) : xtc_get_categories_description_footer($cInfo->categories_id, $languages[$i]['id'])));
									echo xtc_wysiwyg('categories_description_footer[' . $languages[$i]['id'] . ']');
									?>
								</td>
							</tr>
							<tr>
								<td class="main" valign="top"><?php  echo TEXT_META_TITLE; ?></td>
								<td class="main" valign="middle">
									<?php echo xtc_image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']); ?>&nbsp;
									<?php echo xtc_draw_input_field('categories_meta_title[' . $languages[$i]['id'] . ']',(($categories_meta_title[$languages[$i]['id']]) ? stripslashes($categories_meta_title[$languages[$i]['id']]) : xtc_get_categories_meta_title($cInfo->categories_id, $languages[$i]['id'])), 'size=50'); ?> 
								</td>
							</tr>
							<tr>
								<td class="main" valign="top"><?php  echo TEXT_META_DESCRIPTION; ?></td>
								<td class="main" valign="middle">
									<?php echo xtc_image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']); ?>&nbsp;
									<?php echo xtc_draw_input_field('categories_meta_description[' . $languages[$i]['id'] . ']', (($categories_meta_description[$languages[$i]['id']]) ? stripslashes($categories_meta_description[$languages[$i]['id']]) : xtc_get_categories_meta_description($cInfo->categories_id, $languages[$i]['id'])),'size=50'); ?>
							</td>
						</tr>
						<tr>
							<td class="main" valign="top"><?php  echo TEXT_META_KEYWORDS; ?></td>
							<td class="main" valign="middle">
								<?php echo xtc_image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']); ?>&nbsp;
								<?php echo xtc_draw_input_field('categories_meta_keywords[' . $languages[$i]['id'] . ']',(($categories_meta_keywords[$languages[$i]['id']]) ? stripslashes($categories_meta_keywords[$languages[$i]['id']]) : xtc_get_categories_meta_keywords($cInfo->categories_id, $languages[$i]['id'])),'size=50'); ?>
							</td>
						</tr>
					</table>
				</div>
			<?php } ?>
		</div><br />
		<h3>Kategorie Bild</h3>
		<table width="100%" border="0">
			<tr>
				<td class="main" width="200" valign="top">
				<?php if ($cInfo->categories_image) { ?>
					<img class="categories_img" src="<?php echo DIR_WS_CATALOG.'images/categories/'.$cInfo->categories_image; ?>" alt="" />
				<?php } ?>
				</td>
				<td class="main">
					<table width="100%">
						<tr>
							<td class="main">Bild suchen:</td>
							<td class="main">
								<?php echo  xtc_draw_file_field('categories_image').xtc_draw_hidden_field('categories_previous_image', $cInfo->categories_image); ?>
							</td>
						</tr>
						<?php for ($i=0; $i<sizeof($languages); $i++) { ?>
						<tr>
							<td class="main">Alternativtext:</td>
							<td class="main">
								<?php echo xtc_image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']).'&nbsp;'.xtc_draw_input_field('categories_pic_alt[' . $languages[$i]['id'] . ']',(($categories_pic_alt[$languages[$i]['id']]) ? stripslashes($categories_pic_alt[$languages[$i]['id']]) : xtc_get_categories_pic_alt($cInfo->categories_id, $languages[$i]['id'])), 'size=30'); ?>
							</td>
						</tr>
						<?php } if ($cInfo->categories_image) { ?>
						<tr>
							<td class="main">&nbsp;</td>
							<td class="main">
								<?php echo $cInfo->categories_image. '&nbsp;' .xtc_draw_selection_field('del_cat_pic', 'checkbox', 'yes').TEXT_DELETE; ?>
							</td>
						</tr>
						<?php } ?>
					</table>
				</td>
			</tr>
		</table>
		<?php echo xtc_draw_hidden_field('categories_date_added', (($cInfo->date_added) ? $cInfo->date_added : date('Y-m-d'))) . xtc_draw_hidden_field('parent_id', $cInfo->parent_id); ?> 
		<?php echo xtc_draw_hidden_field('categories_id', $cInfo->categories_id); ?> 
	</td>
</tr>
<tr>
	<td colspan="2" align="right">
		<input type="submit" class="button" name="update_category" value="<?php echo BUTTON_SAVE; ?>" style="cursor:pointer">&nbsp;&nbsp;
		<?php echo'<a class="button" onclick="javascript:this.blur()" href="'. xtc_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $_GET['cID']) . '">' . BUTTON_CANCEL . '</a>'; ?>
	</td>
</tr>
</form>